/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine - graphics
// Copyright (c) 2014.  All Rights Reserved
//
// File:		AERenderContextContainer.cpp
// Author:		Gianluca Belardelli
// Date:		08/09/2014
//
/////////////////////////////////////////////////////////////////////////
#include <AEEngine.h>

AERenderContextContainer::AERenderContextContainer( void )
{
}

void AERenderContextContainer::AddContext( AERenderContext *lpContext )
{
	if( m_arrContexts.IndexOf( lpContext ) > -1 )
		return;

	m_arrContexts.PushBack( lpContext );
	SortByPriorities();
}

AEBOOL32 AERenderContextContainer::RemoveContext( AERenderContext *lpContext )
{
	AEINT32 nIdx = m_arrContexts.IndexOf( lpContext );
	if( nIdx >= 0 )
	{
		m_arrContexts.RemoveAt( nIdx );
		return AETRUE;
	}

	return AEFALSE;
}

AEBOOL32 AERenderContextContainer::IsContextRegistered( AERenderContext *lpContext) const
{
	return ( m_arrContexts.IndexOf( lpContext ) < 0 ? AEFALSE : AETRUE );
}

void AERenderContextContainer::RemoveAllContexts( void )
{
	m_arrContexts.Clear();
}

void AERenderContextContainer::PerformVisibilityTests( void )
{
}

void AERenderContextContainer::RenderContexts( AEFLOAT32 fMinPriority, AEFLOAT32 fMaxPriority )
{
	for( AEUINT32 i=0; i<m_arrContexts.GetSize(); i++ )
	{
		AERenderContext *lpContext = m_arrContexts[i];
		const AEFLOAT32 fPriority = lpContext->GetPriority();
		
		if( fPriority >= fMinPriority && fPriority <= fMaxPriority )
		{
			AERenderContext::m_lpCurrentContext = lpContext;
			lpContext->Execute();
		}
	}
}

void AERenderContextContainer::SortByPriorities( void )
{
	
}
